package controllers.admin.System;

import controllers.admin.Logo;
import models.SystemModels.SystemDesign;
import net.sf.json.JSON;
import net.sf.json.JSONObject;

import java.util.List;

/**
 * Created by Administrator on 2018-08-03.
 */
public class Admin_Design extends Logo{

    public static void index(){
        List<models.SystemModels.SystemDesign> list =  models.SystemModels.SystemDesign.findAll();
        List<models.SystemModels.SystemDesign> list1 =  models.SystemModels.SystemDesign.findAll();
        render(list,list1);
    }

    public static void  createData(){
        JSONObject json = new JSONObject();
       try{
           String ImageNames = params.get("ImageNames");
           String ImageWidth = params.get("ImageWidth");
           String ImageHeght = params.get("ImageHeght");
           String ImageCompany = params.get("ImageCompany");
           SystemDesign systemDesign= new SystemDesign();
           systemDesign.ImageCompany = ImageCompany;
           systemDesign.ImageNames = ImageNames;
           systemDesign.ImageHeght = Double.parseDouble(ImageHeght);
           systemDesign.ImageWidth =Double.parseDouble(ImageWidth);
           systemDesign.save();
           json.put("code",1);
       }catch (Exception ex){
           json.put("code",0);
       }
        renderJSON(json);
    }

    public static void delData(){
        JSONObject json = new JSONObject();
        try{
            SystemDesign systemDesign = new SystemDesign();
            systemDesign.delete();
            json.put("code",1);
        }catch (Exception ex){
            json.put("code",0);
        }
        renderJSON(json);
    }

    public static void updateData(){
        JSONObject json = new JSONObject();
        try{
            Long id= Long.parseLong(params.get("Id"));
            String ImageNames = params.get("ImageNames");
            String ImageWidth = params.get("ImageWidth");
            String ImageHeght = params.get("ImageHeght");
            String ImageCompany = params.get("ImageCompany");
            SystemDesign systemDesign= SystemDesign.findById(id);
            systemDesign.ImageCompany = ImageCompany;
            systemDesign.ImageNames = ImageNames;
            systemDesign.ImageHeght = Double.parseDouble(ImageHeght);
            systemDesign.ImageWidth =Double.parseDouble(ImageWidth);
            systemDesign.save();
            json.put("code",1);
        }catch (Exception ex){
            json.put("code",0);
        }
    }
}
